package com.fau.wm.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 储位表-架表
 * @author liy
 * @datetime 2014年7月27日,下午4:23:40
 */
@Entity
@Table(name = "medical_shelf")
public class MedicalShelf implements Serializable,JSONAware {

	private static final long serialVersionUID = 8217022157951306090L;
	
	private String id;
	private String shelfNum;		// 货架编号
	private String warehouseId;		// 仓库id
	private MedicalWarehouse warehouse;
	
	public MedicalShelf() {}
	
	public MedicalShelf(String shelfNum,MedicalWarehouse warehouse) {
		this.shelfNum = shelfNum;
		this.warehouse = warehouse;
	}
	
	public MedicalShelf(String shelfNum,String warehouseId) {
		this.shelfNum = shelfNum;
		this.warehouseId = warehouseId;
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	@Transient
	public String getWarehouseId() {
		return warehouseId;
	}
	
	public void setWarehouseId(String warehouseId) {
		this.warehouseId = warehouseId;
	}

	@ManyToOne
	@JoinColumn(name = "warehouse_id")
	public MedicalWarehouse getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(MedicalWarehouse warehouse) {
		this.warehouse = warehouse;
	}

	@Column(name = "shelf_num", length = 30)
	public String getShelfNum() {
		return shelfNum;
	}

	public void setShelfNum(String shelfNum) {
		this.shelfNum = shelfNum;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("shelfNum", shelfNum);
		obj.put("warehouseId", warehouse.getId());
		obj.put("warehouseName", warehouse.getName());
		return obj.toString();
	}
	
}
